Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ngql websocket #403

Merged
merged 7 commits into from
Jan 6, 2023
Merged

feat: ngql websocket #403

merged 7 commits into from
Jan 6, 2023

Conversation

huaxiabuluo
Copy link
Contributor

@huaxiabuluo huaxiabuluo commented Dec 17, 2022

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

Description:

How do you solve it?

Special notes for your reviewer, ex. impact of this fix, design document, etc:

app/stores/global.ts Outdated Show resolved Hide resolved
@huaxiabuluo huaxiabuluo added the do not review PR: not ready for the code review yet label Dec 20, 2022
@huaxiabuluo huaxiabuluo requested a review from veezhang December 22, 2022 07:26
@huaxiabuluo huaxiabuluo removed the do not review PR: not ready for the code review yet label Dec 23, 2022
Comment on lines +83 to +85
if err == nil {
clientInfo, _ = auth.Decode(tokenCookie.Value, svcCtx.Config.Auth.AccessSecret)
}
Copy link
Contributor

@kqzh kqzh Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil, need handle err? and why ingore auth.Decode err

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should make sure websocket connecting succeed

Comment on lines 71 to 74
msgPost := MessagePost{}
msgPost.Header.MsgId = msgReceived.Header.MsgId
msgPost.Header.SendTime = time.Now().UnixMilli()
msgPost.Body.MsgType = msgReceived.Body.MsgType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge into one declaration? like

msgPost := MessagePost{
    ...
}

Comment on lines 83 to 89
reqParamList := msgReceived.Body.Content["paramList"]
if reqParamList != nil && reflect.TypeOf(reqParamList).Kind() == reflect.Slice {
s := reqParamList.([]interface{})
for i := 0; i < len(s); i++ {
paramList = append(paramList, s[i].(string))
}
}
Copy link
Contributor

@kqzh kqzh Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use

reqParamList, ok := msgReceived.Body.Content["paramList"].([]interface{})
if ok {
    paramList = append(paramList, reqParamList[i].(string)...)
}

instead ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kqzh []any?

Comment on lines 76 to 81
gql, paramList := "", []string{}

reqGql := msgReceived.Body.Content["gql"]
if reqGql != nil {
gql, _ = reqGql.(string)
}
Copy link
Contributor

@kqzh kqzh Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use

reqGql, ok := msgReceived.Body.Content["gql"].(string)
if ok {
  gql = reqGql
}

instead ?

}

execute, _, err := dao.Execute(c.clientInfo.NSID, gql, paramList)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this empty line?

if auth.IsSessionError(err) {
content["code"] = ecode.ErrSession.GetCode()
}
msgPost.Body.Content = &content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add &?

Comment on lines 115 to 118
msgPost := MessagePost{}
msgPost.Header.MsgId = msgReceived.Header.MsgId
msgPost.Header.SendTime = time.Now().UnixMilli()
msgPost.Body.MsgType = msgReceived.Body.MsgType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as runNgql

Comment on lines +168 to +172
msgPost.Body.Content = map[string]any{
"code": base.Success,
"data": resContentData,
"message": "Success",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execute batch ngql will never failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, single ngql execution may be error res, batch req should never fail unless network anomaly or other unexpected server error

Comment on lines 38 to 47
case message := <-h.broadcast:
for client := range h.clients {
select {
case client.send <- message:
default:
close(client.send)
delete(h.clients, client)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has been commented out, may be used in future


reqGql := msgReceived.Body.Content["gql"]
if reqGql != nil {
gql, _ = reqGql.(string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's should not to be ignored. How about you ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msgReceived.Body.Content["gql"] may be a nil value in some case, only paramList is passed in request data

"strings"
"time"

"github.com/gorilla/websocket"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to lint ?

pingPeriod = (pongWait * 9) / 10

// Maximum message size allowed from peer.
maxMessageSize = 16 * 1024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 16 * 1024 enough?

if reqParamList != nil && reflect.TypeOf(reqParamList).Kind() == reflect.Slice {
s := reqParamList.([]interface{})
for i := 0; i < len(s); i++ {
paramList = append(paramList, s[i].(string))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s[i] maybe not a string ?

}
}

msgSend, _ := json.Marshal(msgPost)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check the error?

Comment on lines 123 to 129
reqGqls := msgReceived.Body.Content["gqls"]
if reqGqls != nil && reflect.TypeOf(reqGqls).Kind() == reflect.Slice {
s := reqGqls.([]interface{})
for i := 0; i < len(s); i++ {
gqls = append(gqls, s[i].(string))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some functions for MessageReceiveBody is more clearer?
And check the type in those functions.

func (b *MessageReceiveBody) GetGqls() (string, error) {
}
func (b *MessageReceiveBody) GetParamList() ([]string, error) {
}
// and so on 

break
}

msgReceivedStr := bytes.TrimSpace(bytes.Replace(message, newline, space, -1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need bytes.Replace(message, newline, space, -1)?

}
w.Write(message)

// Add queued chat messages to the current websocket message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chat messages?

// Add queued chat messages to the current websocket message.
n := len(c.send)
for i := 0; i < n; i++ {
w.Write(newline)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to write newline ?

}
}

// ServeWs handles websocket requests from the peer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServeWs => ServeWebSocket?

clients map[*Client]bool

// Inbound messages from the clients.
broadcast chan []byte
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what?

Copy link
Contributor

@hetao92 hetao92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hetao92 hetao92 merged commit 48e138d into vesoft-inc:master Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants